import datetime

from django.contrib.admin.templatetags.admin_list import pagination
from django.http import HttpResponse

from django.shortcuts import render, get_object_or_404
from django.views import View
from django.views.generic import TemplateView, ListView, DetailView
from django.core.paginator import Paginator,Page
from main.models import *
# Create your views here.

# class HomeTemplateView(TemplateView):
#         # template_name = "index.html"
#     extra_context = {
#             'title': 'Django 测试',
#             'content': 'Django 测试内容'
#         }
#     def get_template_names(self):
#         return ['index.html']
def index(request):
    datas = DesignModel.objects.all()
    paginator = Paginator(datas, 3)
    # print(paginator.num_pages)
    # print(paginator.page_range)
    # print(paginator.count)

    pn = request.GET.get('pn',1)



    page = paginator.page(pn)
    # print(page_two.number)
    # print(page_two.object_list)
    # print(page_two.has_next())
    # print(page_two.has_previous())




    return  render(request,'index.html',{'page':page})
class IndexView(View):
    def get(self,request):
        context = {
            'title': 'Django 测试',
            'content': 'Django 测试内容',
            'now': datetime.datetime.now()
        }


    # p = Publication()
    # # a0 = Article()
    # # a = Article.objects
    # a0 = Article.objects.all()
    # a = Article.objects.all().first()
    # a1 = Article.objects.get(id=1)
    # # print(p0,'1111')
    # # print(p,'2222')
    # # print(p1)
    # print(a0)
    # print(a,'222')
    # print(a.publications.all())
    # a = Article()
    # b = Article.objects
    # print(b,'111111')
    # print(a.objects,'3333333')
    # a = Article.objects.all()
    # p = Publication.objects.all().first()
    # print(p)
    # print(p.article_set.all())
    # ppp = Person.objects.all()
    # pp = Person.person.all()
    # print(pp)
    # print(ppp)

    # p = Person.objects.all().filter(name='黄本贵')
    # print(p)
    # p = Person.objects.all().exclude(name='黄本贵')
    # print(p)


    #字段查询
    # print(Person.objects.filter(name__contains='黄'),'1111')
    # print(Person.objects.all().filter(id__lte=5),'2222')
    # print(Person.objects,'3333')

    # print(get_object_or_404(Person, id=2))

class DesignModelListView(ListView):
    model = DesignModel
    # def get_queryset(self):
    #     return DesignModel.objects.all()
    # queryset = DesignModel.objects.all()



    template_name = "list.html"
    # context_object_name = "datas"
    def get_context_object_name(self, object_list):
        return "data"
    extra_context = {
        'title': 'Django 测试',
        'content': 'Django 测试内容',
        'now': datetime.datetime.now()
    }
    def get_context_data(self, **kwargs):
        kwargs = super().get_context_data( **kwargs)
        kwargs.update({"name": "黄本贵","age":"18"})
        return kwargs

class DesignModelDetailView(DetailView):
    model = DesignModel
    template_name = "detail.html"


